package com.team.dao;



import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.team.entity.Folder;
import com.team.util.DbHelp;
import com.team.util.ResultSetPackge;

public class FolderDao {
	DbHelp<Folder> db = new DbHelp<Folder>();
	
	public int saveFolder(Folder folder){
		String sql = "insert into t_filetype(filetypename,createtime,t_user_id,t_project_id)values(?,?,?,?)";
		return db.executeUpdateSql(sql, folder.getFiletypename(),folder.getCreatetime(),folder.getUserId(),folder.getProjId());
	}
	
	public List<Folder>selectAllFolders(){
		String sql = "select id,filetypename,createtime,t_user_id,t_project_id from t_filetype";
		return  db.exeSelectForList(sql, new PackgeFolder());
	}

	public Folder selectFolder(int id){
		
		String sql = "select id,filetypename,createtime,t_user_id,t_project_id from t_filetype where id = ?";
		return db.exeSelectForObject(sql, new PackgeFolder(), id);
		
	}
	private class PackgeFolder implements ResultSetPackge<Folder>{

		public Folder packgeResultSet(ResultSet rs) throws SQLException {
			Folder folder = new Folder();
			folder.setId(rs.getInt("id"));
			folder.setCreatetime(rs.getString("createtime"));
			folder.setFiletypename(rs.getString("filetypename"));
			folder.setUserId(rs.getInt("t_user_id"));
			folder.setProjId(rs.getInt("t_project_id"));
			return folder;
			
		}
		
	}
}